#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main()
{
int fd[2]={0};
int ret=pipe(fd); 
int pid=fork();
if(pid==0)
{
//子进程
close(fd[1]);
char buff[128];
while(1)
{
int n=read(fd[0],buff,sizeof(buff)-1);
if(n==0)
{
  printf("读到末尾了\n");
}
else if(n>0)
{
buff[n]='\0';
printf("子进程：%s\n",buff);
}
else{
printf("error\n");
}
sleep(1);
}
}
else
{
//父进程
close(fd[0]);
char buff[128]={0};
while(1)
{
sprintf(buff,"我是父进程，我是写入者");
int ret=write(fd[1],buff,strlen(buff));
sleep(1);



}
}



  return 0;
}
